import pandas as pd
from django.conf import settings

def readfundInfo(code):
        filename = settings.FUND_PRICE_DIR + "/" + code + ".csv"
        df = pd.read_csv(filename)
        df.columns = ["date", "jjjz", "ljjz"] #读取到的csv文件没有表头，重新设置表头
        return df       

def getMeanDf(code, window, min):
      df = readfundInfo(code)
      df["ref"] = df['ljjz'].rolling(window=window, min_periods=min).mean()
      return df







def test():
    return
    #df = getMeanDf("005918")
    testStrategie("005918", 22, 1000, 2500, 2500, 2, 1)
    testStrategie("005918", 22, 1000, 2500, 220, 2, 1)
    testStrategie("005918", 22, 1000, 2500, 110, 2, 1)
    testStrategie("005918", 22, 1000, 2500, 22, 2, 1)

    testStrategie("005918", 22, 1000, 2500, 2500, 2, 11)

    print("=============================================")

    testStrategie("001917", 22, 1000, 2500, 2500, 2, 1)
    testStrategie("001917", 22, 1000, 2500, 220, 2, 1)
    testStrategie("001917", 22, 1000, 2500, 110, 2, 1)
    testStrategie("001917", 22, 1000, 2500, 22, 2, 1)
    testStrategie("001917", 22, 1000, 2500, 22, 2, 11)

    print("=============================================")

    testStrategie("008115", 22, 1000, 2500, 2500, 2, 1)
    testStrategie("008115", 22, 1000, 2500, 220, 2, 1)
    testStrategie("008115", 22, 1000, 2500, 110, 2, 1)
    testStrategie("008115", 22, 1000, 2500, 22, 2, 1)
    testStrategie("008115", 22, 1000, 2500, 22, 2, 11)

    print("=============================================")

    testStrategie("121010", 22, 1000, 2500, 2500, 2, 1)
    testStrategie("121010", 22, 1000, 2500, 220, 2, 1)
    testStrategie("121010", 22, 1000, 2500, 110, 2, 1)
    testStrategie("121010", 22, 1000, 2500, 22, 2, 1)
    testStrategie("121010", 22, 1000, 2500, 22, 2, 11)

    print("---------------------------------------------")

    #print(df)
